﻿// MIT License
// 开源地址：https://gitee.com/co1024/AbcMvc
// Copyright (c) 2021-2023 1024
// Abc.Mvc=Furion+EF+SqlSugar+Pear layui admin.

namespace Abc.Core.Entities;

/// <summary>
///     邮件发送记录
/// </summary>
[Comment("邮件发送记录")]
[Table("Sys_EmailSendRecord")]
public class EmailSendRecord : EFFullEntity, IEntityTypeBuilder<EmailSendRecord>
{
    /// <summary>
    ///     Json数据 <see cref="Dictionary<string, object>"/>
    /// </summary>
    [Comment("Json数据")]
    public string ExtensionData { get; set; }

    /// <summary>
    ///     关联ID
    /// </summary>
    [Comment("关联ID")]
    public long DataId { get; set; }

    ///// <summary>
    ///// 邮件类型
    ///// </summary>
    //[Comment("邮件类型")]
    //public EmailSendType Type { get; set; }
    /// <summary>
    ///     邮件模板类型
    /// </summary>
    [Comment("邮件模板类型")]
    public EmailTemplateType TemplateType { get; set; }

    /// <summary>
    ///     主题
    /// </summary>
    [Comment("主题")]
    [MaxLength(300)]
    public string Subject { get; set; }

    /// <summary>
    ///     内容
    /// </summary>
    [Comment("内容")]
    public string Content { get; set; }

    /// <summary>
    ///     收件人
    /// </summary>
    [Comment("收件人")]
    [MaxLength(100)]
    public string ReceiveName { get; set; }

    /// <summary>
    ///     收件邮箱
    /// </summary>
    [Comment("收件邮箱")]
    [MaxLength(100)]
    public string ReceiveEmail { get; set; }

    /// <summary>
    ///     邮件发送状态
    /// </summary>
    [Comment("邮件发送状态")]
    public EmailSendState State { get; set; }

    /// <summary>
    ///     发送结果
    /// </summary>
    [Comment("发送结果")]
    [MaxLength(500)]
    public string SendResult { get; set; }

    /// <summary>
    ///     发送次数
    /// </summary>
    [Comment("发送次数")]
    public int SendNum { get; set; }

    /// <summary>
    ///     最大发送次数
    /// </summary>
    [Comment("最大发送次数")]
    public int SendMaxNum { get; set; }

    /// <summary>
    ///     验证码
    /// </summary>
    [Comment("验证码")]
    public string VerCode { get; set; }

    /// <summary>
    ///     是否使用
    /// </summary>
    [Comment("是否使用")]
    public bool IsUse { get; set; }

    /// <summary>
    ///     过期时间
    /// </summary>
    [Comment("过期时间")]
    public DateTimeOffset? ExpireTime { get; set; }

    public void Configure(EntityTypeBuilder<EmailSendRecord> entityBuilder, DbContext dbContext, Type dbContextLocator)
    {
        entityBuilder.HasIndex(o => o.DataId);
        entityBuilder.HasIndex(o => o.SenderEmail);
        entityBuilder.HasIndex(o => o.ReceiveEmail);
    }

    #region 防止后期修改了，就不知道了

    /// <summary>
    ///     邮件发送名称
    /// </summary>
    [Comment("邮件发送名称")]
    [MaxLength(100)]
    public string SenderName { get; set; }

    /// <summary>
    ///     邮件发送账号
    /// </summary>
    [Comment("邮件发送账号")]
    [MaxLength(100)]
    public string SenderEmail { get; set; }

    #endregion 防止后期修改了，就不知道了
}

/// <summary>
///     邮件类型
/// </summary>
public enum EmailSendType
{
    系统邮件 = 0
}

public enum EmailSendState
{
    未发送 = 0,
    已发送 = 1,
    发送失败 = 2
}